<html>
<head>
    <title>机构管理</title>
	<#include "/common/import.ftl" >
    <script type="text/javascript" src="${ctx}/js/easyui/extendvalidate.js"></script>
    <script src="${ctx}/js/uct_dict.js"></script>
    <script type="text/javascript" src="${ctx}/js/date.js"></script>
    <script type="text/javascript" src="${ctx}/js/utiltools.js"></script>
    <script>

        $(function () {
            $('#orgSaveForm').form({
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (data) {
                    var result = jQuery.parseJSON(data);
                    if (result.flag == 'T') {
                        $.messager.alert('提交结果', '操作成功', 'info', function () {
                            parent.closeOrgWindow();
                            if ("0" == "${item.fatherId!''}") {
                                parent.reload();
                            } else {
                                parent.reloadTree('${item.fatherId!""}', '${item.orgId!""}');
                            }
                        });
                    } else {
                        $.messager.alert('提交结果', result.msg, 'info');
                    }
                }
            });

            if ("${item.orgId!''}" != null && "${item.orgId!''}" != "") {
                $("#item.orgEname").attr("readonly", true);
            }

        });


        $.extend($.fn.validatebox.defaults.rules, {
            minLength: {
                validator: function (value, param) {
                    return value.length >= param[0];
                },
                message: 'Please enter at least {0} characters.'
            }
        });


    </script>

<body>

<div id="tip"></div>
<form id="orgSaveForm" name="orgSaveForm" method="post" action="save.action">
    <input type="hidden" name="formToken" id="formToken" value="${formToken!''}">
    <input type="hidden" name="orgId" id="orgId" value="${item.orgId!''}"/>
    <input type="hidden" name="fatherId" id="fatherId" value="${item.fatherId!''}"/>
    <input type="hidden" name="updateCount" id="updateCount" value="${item.updateCount!''}"/>
    <input type="hidden" name="sysEname" id="sysEname" value="${item.sysEname!''}"/>
    <input type="hidden" name="subCount" id="subCount" value="${item.subCount!''}"/>
    <table class="datagrid-body">
        <tr>
            <td class="datagrid-header">机构名称<span style="color:red;">*</span></td>
            <td>
                <input name="orgCname" id="orgCname" value="${item.orgCname!''}"
                       class="easyui-validatebox" required="true" size="30" validType="length[2,30]"
                       missingMessage="请输入机构名称" invalidMessage="应为2~30个字"/>
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">机构标识<span style="color:red;">*</span></td>
            <td>

                <input id="orgEname" name="orgEname" value="${item.orgEname!''}"
                       class="easyui-validatebox" required="true" size="30"
                       missingMessage="请输入机构标识"/>

            </td>
        </tr>
        <tr>
            <td class="datagrid-header">机构代码<span style="color:red;">*</span></td>
            <td><input id="orgCode" name="orgCode" value="${item.orgCode!''}"
                       class="easyui-validatebox" required="true" size="30" validType="length[0,30]"
                       missingMessage="请输入机构代码" invalidMessage="不能超过30个字"/>
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">所 属 域</td>
            <td><input id="orgDomain" name="orgDomain" value="${item.orgDomain!''}"/>

            </td>
        </tr>
        <tr>
            <td class="datagrid-header">负责人<span style="color:red;">*</span></td>
            <td><input id="boss" name="boss" value="${item.boss!''}"
                       class="easyui-validatebox" required="true" size="30" validType="length[0,30]"
                       invalidMessage="不能超过30个字"/>
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">联系人<span style="color:red;">*</span></td>
            <td><input id="linkMan" name="linkMan" value="${item.linkMan!''}"
                       class="easyui-validatebox" required="true" size="30" validType="length[0,30]"
                       invalidMessage="不能超过30个字"/>
            </td>
        </tr>

        <tr>
            <td class="datagrid-header">联系电话<span style="color:red;">*</span></td>
            <td><input id="phone" name="phone" value="${item.phone!''}"
                       class="easyui-validatebox" required="true" size="30" validType="tel"
            />
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">传真<span style="color:red;">*</span></td>
            <td><input id="fax" name="fax" value="${item.fax!''}"
                       class="easyui-validatebox" required="true" size="30" validType="tel"
                       invalidMessage="请输入正确传真"/>
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">所在省份</td>
            <td>
                <select id="province" name="province" style="width:183px;"></select>
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">所在地区</td>
            <td>
                <select id="city" name="city" style="width:183px;"></select>
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">地址<span style="color:red;">*</span></td>
            <td><input id="address" name="address" value="${item.address!''}"
                       class="easyui-validatebox" required="true" size="30"
                       validType="length[0,100]"
                       invalidMessage="不能超过30个字"/>
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">邮编<span style="color:red;">*</span></td>
            <td><input id="postCode" name="postCode" value="${item.postCode!''}"
                       class="easyui-validatebox" required="true" size="30" validType="ZIP"
            />
            </td>
        </tr>
        <tr>
            <td class="datagrid-header">状态</td>
            <td>
                <input type="radio" name="orgStatus" id="orgStatus_1" value="1"/>启用
                <input type="radio" name="orgStatus" id="orgStatus_0" value="0"/>停用
            </td>
        </tr>


        <tr>
            <td class="datagrid-header"></td>
            <td>
                <input type="submit" value="提交"/>
            </td>
        </tr>

    </table>

</form>
</body>
</html>

<script>
    var webCtx = '${ctx}';
    var dictProvId = 'province';//省份的下拉列表id
    var dictCityId = 'city';//城市的下拉列表id
    loadProvince();
    loadCity('${item.province!""}');

    function loadProvince() {
        $('#' + dictProvId).combobox({
            url: webCtx + '/dict/pub/dict-select.action?cateEname=area&fatherValue=0',
            valueField: 'id',
            editable: false,
            textField: 'text',
            onChange: function () {
                var provinceTmp = $('#' + dictProvId).combobox('getValue');
                loadCity(provinceTmp);
            }
        });
    }

    function loadCity(provinceValue) {
        var cityUrl = webCtx + '/dict/pub/dict-select.action?cateEname=area&fatherValue=' + provinceValue;
        $('#' + dictCityId).combobox({
            url: cityUrl,
            valueField: 'id',
            editable: false,
            textField: 'text'
        });
    }

    $(function () {
        UtilTools.initRadio("orgStatus", "${item.orgStatus!''}");
        setProvinceValue('${item.province!""}');
        setCityValue('${item.city!""}');
    });
</script>